Online-Academy
Look, Read, Understand, Apply

Data Structure

Q and A 2025

What is data structure?

Ans: Data structure is a method to store and organize data such that accessing and manipulating data becomes easily.

What are the different types of data structure?

Ans: Two major types of data structure are:

  1. Linear Data structure
  2. Non-linear Data structure

Stack, Queue and linked lists are linear data structures and Tree, graphs are non-linear Data structure.

What is stack and what are the possible operations with stack?

Ans: Stack is a linear data structure with one end from which insertion and deletion of data is done. That end is termed as “TOP”, top is an integer value which is increased by one to insert element and decremented by one to delete element. In stack last element inserted is the first element to be removed so, it is called Last In First Out (LIFO). Possible operations with stack are

  1. Push: Operation to insert element. In push operation value of TOP is increased by 1 to insert element.
  2. Pop: Operation to delete element from stack. In pop operation value of TOP is decremented by 1 to remove element.
  3. Peek: Operation to display top element (last element inserted).
  4. isEmpty: Operation to check if there is element in stack or not. In empty stack value of top is equal to -1.
  5. isFull: Operation to check if stack is full or not. In full stack value of top is equal to size_of_stack – 1.
  6. Size: Operation to know number of elements in the stack. The value of top + 1 will give the number of elements in the stack.

What is queue and what are the possible operations with queue?

Ans: Queue is a linear data structure with two ends for inserting and removing elements. Those two ends are termed “REAR” and “FRONT” of queue. In queue first element inserted is the first element to be removed so, it is also known as First In First Out (FIFO) data structure.

Possible operations with queue are:

  1. Enqueue: Operation to insert element to the queue. By incrementing value of rear by one, element is inserted in the queue.
  2. Dequeue: Operation to remove element from queue. Value of front is incremented by one to remove element from queue.
  3. Peek: Displaying the front element of queue.
  4. isEmpty: Operation to check if there is an element in queue or not. Value of rear is -1 and front is 0 for empty queue.
  5. isFull: Operation to check if there is any empty space in queue for new element or not. In full queue value of rear is equal to size_of_queue.
  6. >
  7. Size: Operation to know number of elements in the queue. The value of difference between rear and front will give the number of elements in the queue.

What is circular queue?

Ans: Circular queue is a queue in which rear can be incremented to insert new elements to occupy empty space remained after removing elements from the queue.

Explain priority queue.

Ans: Priority queue is a queue in which elements are removed based on the priority of the elements. Elements of the queue are given priority and priority with highest priority is removed first.

Write a module to insert an element to stack.

Let\’s suppose stk be an integer array of size 20 and ele be an element to insert into the stack. Then the module to insert element to stack will be as follows:

public void push(int ele, int[] stk){
	if(isEmpty(stk)){
		stk[top] = ele;
	}else{
		System.out.println(\”Stack is full\”);
}

Write module to remove element from stack.

Let’s suppose que be an integer queue of size twenty. Then the module to insert element to queue will be as follows:

	public void pop(){
		if(isEmpty(que)){
			int x = que[front];
			++front;
}else{
	System.out.println(“Queue is Empty!”);
}	
}